﻿<Window x:Class="VideoEncoder.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Icon="Icon.ico"
    xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WpfToolkit"
    xmlns:app="clr-namespace:VideoEncoder"
    Title="Video Encoder" Height="400" Width="950">
    <Grid>
        <Grid x:Name="rootGrid" Visibility="Collapsed">
            <Grid.Resources>
                <app:ShowProgressStatusConverter x:Key="showProgressStatusConverter" />
                <app:ShowStatusConverter x:Key="showStatusConverter" />
                <app:StatusIsEnablesConverter x:Key="statusIsEnablesConverter" />
                <app:StatusConverter x:Key="statusConverter" />
                <app:ByteConverter x:Key="byteConverter" />
                <app:ShowUpDownConverter x:Key="showUpDownConverter" />
                <Style x:Key="DataGridCellStyle" TargetType="{x:Type dg:DataGridCell}">
                    <Setter Property="BorderThickness" Value="0" />
                </Style>

                <Style x:Key="cancelButton" TargetType="Button">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Button">
                                <Grid>
                                    <Image Name="deleteImage" Source="Images/delete.png" Width="16" />
                                    <Image Name="unabledbutton" Opacity="0" Source="Images/disableddelete.png" Width="16" />
                                </Grid>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsEnabled" Value="False">
                                        <Setter TargetName="deleteImage" Property="Opacity" Value="0" />
                                        <Setter TargetName="unabledbutton" Property="Opacity" Value="1" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <Style x:Key="upButton" TargetType="Button">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Button">
                                <Grid>
                                    <Image Name="upImage" Source="Images/up.png" Width="16" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <Style x:Key="downButton" TargetType="Button">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Button">
                                <Grid>
                                    <Image Name="downImage" Source="Images/down.png" Width="16" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="3" />
                <ColumnDefinition Width="325" />
            </Grid.ColumnDefinitions>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <TextBlock Text="Source Folder:" Grid.Column="0" Margin="3" VerticalAlignment="Center" />

                    <TextBox Grid.Column="1" Margin="3" Text="{Binding SourceFolder}" ></TextBox>
                    <Button x:Name="sourceBrowseButton" Content="Browse" Grid.Column="2" Margin="3" />
                    <Button x:Name="loadButton" Content="Load Files" Grid.Column="3" Margin="3" />
                    <Button x:Name="addFileButton" Content="Add File(s)" Grid.Column="4" Margin="3" />
                </Grid>
                <Grid Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <TextBlock Text="Output Folder:" Grid.Column="0" Margin="3" VerticalAlignment="Center" />

                    <TextBox x:Name="outputTextBox" Text="{Binding OutputFolder}" Grid.Column="1" Margin="3" ></TextBox>
                    <Button x:Name="outputBrowseButton" Content="Browse" Grid.Column="2" Margin="3" />


                </Grid>

                <StackPanel Grid.Row="2" Orientation="Horizontal">
                    <CheckBox x:Name="sameAsSourceCheckBox" IsChecked="{Binding OutputSameAsSource}" Content="Output file to same directory as source file." Margin="3" />
                    <CheckBox x:Name="deleteSourceCheckBox" IsChecked="{Binding DeleteSource}" Content="Delete source file." Margin="3" />
                    <CheckBox x:Name="closeCheckBox" IsChecked="{Binding CloseWhenComplete}" Content="Close when complete." Margin="3" />
                </StackPanel>


                <dg:DataGrid x:Name="itemsQueueDataGrid" Grid.Row="3" Background="White" Margin="3" AutoGenerateColumns="False" AlternatingRowBackground="#ffeeeeee" 
                GridLinesVisibility="None" CellStyle="{StaticResource DataGridCellStyle}">
                    <dg:DataGrid.Columns>
                        <dg:DataGridTemplateColumn>
                            <dg:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Button Tag="{Binding}" Margin="3" Click="Button_Click" Style="{StaticResource cancelButton}" IsEnabled="{Binding Status,Converter={StaticResource statusIsEnablesConverter}}" />
                                        <Button Tag="{Binding}" Margin="3" Click="MoveUp_Click" Style="{StaticResource upButton}" />
                                        <Button Tag="{Binding}" Margin="3" Click="MoveDown_Click" Style="{StaticResource downButton}" />
                                    </StackPanel>
                                </DataTemplate>
                            </dg:DataGridTemplateColumn.CellTemplate>
                        </dg:DataGridTemplateColumn>
                        <dg:DataGridTextColumn Header="Name" Binding="{Binding Name}" IsReadOnly="True"/>
                        <dg:DataGridTemplateColumn Header="Status" IsReadOnly="True" MinWidth="100">
                            <dg:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid Margin="3" Visibility="{Binding Status,Converter={StaticResource showProgressStatusConverter}}">
                                            <ProgressBar Minimum="0" Maximum="100" Value="{Binding Progress}" Height="20" />
                                            <TextBlock Text="{Binding ProgressText}" HorizontalAlignment="Center" Margin="3" />
                                        </Grid>
                                        <TextBlock Text="{Binding Status,Converter={StaticResource statusConverter}}" Visibility="{Binding Status,Converter={StaticResource showStatusConverter}}" />
                                    </Grid>
                                </DataTemplate>
                            </dg:DataGridTemplateColumn.CellTemplate>
                        </dg:DataGridTemplateColumn>
                        <dg:DataGridTextColumn Header="File Duration" Binding="{Binding FileDuration}" IsReadOnly="True"/>
                        <dg:DataGridTextColumn Header="Video Size" Binding="{Binding OriginalVideoSize}" IsReadOnly="True"/>
                        <dg:DataGridTextColumn Header="Frame Rate" Binding="{Binding OriginalFrameRate}" IsReadOnly="True"/>
                        <dg:DataGridTextColumn Header="File Length" Binding="{Binding FileLength,Converter={StaticResource byteConverter}}" IsReadOnly="True"/>
                        <dg:DataGridTextColumn Header="Encode Started" Binding="{Binding StartTime}" IsReadOnly="True"/>
                        <dg:DataGridTextColumn Header="Encode Stopped" Binding="{Binding EndTime}" IsReadOnly="True"/>
                    </dg:DataGrid.Columns>
                </dg:DataGrid>


                <StackPanel Orientation="Horizontal" Grid.Row="4" Grid.ColumnSpan="2" HorizontalAlignment="Center" >
                    <Button x:Name="startButton" Content="Encode" Margin="3" />
                    <Button x:Name="pauseButton" Content="Pause" Margin="3" Visibility="Collapsed" />
                    <Button x:Name="resumeButton" Content="Resume" Margin="3" Visibility="Collapsed" />
                    <Button x:Name="cancelButton" Content="Cancel" Margin="3" Visibility="Collapsed" />
                </StackPanel>

            </Grid>
            <GridSplitter Grid.Column="1" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  />
            <ScrollViewer Grid.Column="2" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
                <Grid x:Name="profilesGrid">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Expander x:Name="defaultProfilesExpander" IsExpanded="True" >
                        <Expander.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock Text="Default Profiles" FontWeight="Bold" />
                            </DataTemplate>
                        </Expander.HeaderTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <TextBlock Grid.Row="0" Text="Default Video Profile:" Margin="3" />
                            <ComboBox Grid.Row="1" x:Name="videoProfileCombo" DisplayMemberPath="Name" Margin="3" />
                            <TextBlock Grid.Row="2" Text="Default Audio Profile:" Margin="3" />
                            <ComboBox Grid.Row="3" x:Name="audioProfileCombo" DisplayMemberPath="Name" Margin="3" />

                            <StackPanel Grid.Row="4" Orientation="Horizontal">
                                <TextBlock Text="Default Video Complexity" HorizontalAlignment="Right" Margin="3" />
                                <ComboBox x:Name="videoComplexityCombo" Margin="3" />
                            </StackPanel>

                        </Grid>
                    </Expander>
                    <Expander Grid.Row="1" x:Name="selectedMediaItemGrid" Visibility="Collapsed" IsExpanded="True">
                        <Expander.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock Text="Profile Settings" FontWeight="Bold" />
                            </DataTemplate>
                        </Expander.HeaderTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <TextBlock Text="Video Profile:" FontWeight="Bold" Margin="3" />
                            <app:VideoProfileControl Grid.Row="1" x:Name="videoProfile" Margin="3" />
                            <TextBlock Grid.Row="2" Text="Audio Profile:" FontWeight="Bold" Margin="3"  />
                            <app:AudioProfileControl Grid.Row="3" x:Name="audioProfile" Margin="3" />

                            <StackPanel Grid.Row="4" Orientation="Horizontal">
                                <TextBlock Text="Projected File Size:" Margin="3" />
                                <TextBlock x:Name="projectedFileSizeTextBlock" Margin="3" Text="{Binding OutputFileEstimatedSize,Converter={StaticResource byteConverter}}" />
                            </StackPanel>

                        </Grid>
                    </Expander>
                </Grid>
            </ScrollViewer>
        </Grid>
        <Grid x:Name="loadingGrid">
            <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Text="Loading..." HorizontalAlignment="Center" VerticalAlignment="Center" />
                <ProgressBar IsIndeterminate="True" Width="70" Height="15" />
            </StackPanel>
        </Grid>
    </Grid>
</Window>
